<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
</head>
<body>

<h1 id="user"></h1>
<h1 id="identity"></h1>
<img id="imageUrl"/>

<button class="bt" style="display: none">前往登录</button>
<button class="bt" style="display: none" onclick="location.href = 'register.html'">前往注册</button>

</body>
</html>
<script>
    window.onload = function () {

        if (!localStorage.getItem("user")){
            const bts = document.getElementsByClassName("bt");
            for (let i = 0; i < bts.length; i++) {
                bts[i].style.display = "block";
            }
        }else {
            const userStr = localStorage.getItem("user")
            const user = JSON.parse(userStr)
            if (user.identity === 1){
                document.getElementById("identity").innerHTML = '学生'
            }
            document.getElementById("username").innerHTML = user.username
            document.getElementById("imageUrl").src = user.imageUrl
        }


    }
</script>